<%--
  Created by IntelliJ IDEA.
  User: lzy
  Date: 2020/8/4
  Time: 下午3:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Test</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script src="http://libs.baidu.com/jquery/1.7.2/jquery.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#btn1").click(function () {
                const max = 30000;
                for (let i = 1; i <= max; i++) {
                    let url = "http://localhost:8080/userRedPacket/grabRedPacket?redPacketId=1&userId=" + i;
                    // jQuery的post请求,采用异步方式
                    $.post(
                        //请求抢id为1的红包
                        url,
                        // 成功后方法
                        function (data, status) {

                        });
                }
            });

            $("#btn2").click(function () {
                const max = 30000;
                for (let i = 1; i <= max; i++) {
                    let url = "http://localhost:8080/userRedPacket/grabRedPacketForVersion?redPacketId=1&userId=" + i;
                    // jQuery的post请求,采用异步方式
                    $.post(
                        //请求抢id为1的红包
                        url,
                        // 成功后方法
                        function (data, status) {

                        });
                }
            });

            $("#btn3").click(function () {
                const max = 30000;
                for (let i = 1; i <= max; i++) {
                    let url = "http://localhost:8080/userRedPacket/grabRedPacketByRedis?redPacketId=5&userId=" + i;
                    // jQuery的post请求,采用异步方式
                    $.post(
                        //请求抢id为1的红包
                        url,
                        // 成功后方法
                        function (data, status) {

                        });
                }
            });
        });

    </script>
</head>
<body>
<h1>Test Red Packet</h1>
<br/><br/>
<button type="button" id="btn1">悲观锁 start test</button>
<br><br>
<button type="button" id="btn2">乐观锁 start test</button>
<br><br>
<button type="button" id="btn3">redis start test</button>
</body>
</html>
